package com.itcoon.transform4j.demo.web.controller;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.itcoon.common.web.core.response.ApiResponse;
import com.itcoon.transform4j.demo.domain.Room;
import com.itcoon.transform4j.demo.web.vo.OrderVCO;
import com.itcoon.transform4j.demo.web.vo.RoomVCO;
import com.itcoon.transform4j.demo.web.vo.RoomVIO;
import com.itcoon.transform.starter.Transformer;
import com.itcoon.transform4j.demo.domain.Order;
import com.itcoon.transform4j.demo.domain.Status;
import com.itcoon.transform4j.demo.domain.Student;
import com.itcoon.transform4j.demo.web.vo.OrderVIO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;

@Api(tags = "04_assemble_进阶篇", description = "内含多个集合属性，数组，map， 多种数据类型")
@RestController
@RequestMapping("/api")
public class ComplexAssembleController {

    @ApiOperation("获取宿舍(对象内嵌套另一个对象数组和集合，目标对象为接口定义)")
    @GetMapping("/room1")
    public ApiResponse<RoomVIO> getRoom(){
        Room room = new Room();
        room.setNo("202");

        Student student1 = new Student();
        student1.setSid(1L);
        student1.setName("张三");

        Student student2 = new Student();
        student2.setSid(2L);
        student2.setName("李四");

        Student student3 = new Student();
        student3.setSid(3L);
        student3.setName("王五");

        Student student4 = new Student();
        student4.setSid(4L);
        student4.setName("赵六");

        List<Student> studentList = Lists.newArrayList(student1, student2);
        Student[] students = new Student[]{student3, student4};
        room.setStudentList(studentList);
        room.setStudents(students);
        room.setTags(new String[]{"干净", "整齐"});

        Map<String,Student> studentMap = Maps.newTreeMap();
        studentMap.put("刘维维", student1);
        studentMap.put("张强", student2);
        studentMap.put("韩伟", student3);
        room.setStudentMap(studentMap);

        RoomVIO roomVIO = Transformer.to(RoomVIO.class).apply(room).done();
        return ApiResponse.createSuccess(roomVIO);
    }

    @ApiOperation("获取宿舍(对象内嵌套另一个对象数组和集合, 目标对象为类定义)")
    @GetMapping("/room2")
    public ApiResponse<RoomVCO> getRoom2(){
        Room room = new Room();
        room.setNo("202");

        Student student1 = new Student();
        student1.setSid(1L);
        student1.setName("张三");

        Student student2 = new Student();
        student2.setSid(2L);
        student2.setName("李四");

        Student student3 = new Student();
        student3.setSid(3L);
        student3.setName("王五");

        Student student4 = new Student();
        student4.setSid(4L);
        student4.setName("赵六");

        List<Student> studentList = Lists.newArrayList(student1, student2);
        Student[] students = new Student[]{student3, student4};
        room.setStudentList(studentList);
        room.setStudents(students);
        room.setTags(new String[]{"干净", "整齐"});

        Map<String,Student> studentMap = Maps.newTreeMap();
        studentMap.put("刘维维", student1);
        studentMap.put("张强", student2);
        studentMap.put("韩伟", student3);
        room.setStudentMap(studentMap);


        RoomVCO roomVCO = Transformer.to(RoomVCO.class).apply(room).done();
        return ApiResponse.createSuccess(roomVCO);
    }

    @ApiOperation("获取订单(内含多个不同类型的数据， 目标对象为接口定义)")
    @GetMapping("/order1")
    public ApiResponse<OrderVIO> getOrder1(){
        Order order = new Order();
        order.setId(1L);
        order.setAmount(BigDecimal.valueOf(99.99));
        order.setPayTime(LocalDateTime.now());
        order.setStatuses(Lists.newArrayList(Status.FREEZEN, Status.PAY_FAILURE));
        order.setCreationTime(ZonedDateTime.now());
        OrderVIO orderVIO = Transformer.to(OrderVIO.class).apply(order).done();
        return ApiResponse.createSuccess(orderVIO);
    }


    @ApiOperation("获取订单(内含多个不同类型的数据， 目标对象为接口定义)")
    @GetMapping("/order2")
    public ApiResponse<OrderVCO> getOrder2(){
        Order order = new Order();
        order.setId(1L);
        order.setAmount(BigDecimal.valueOf(99.99));
        order.setPayTime(LocalDateTime.now());
        order.setStatuses(Lists.newArrayList(Status.FREEZEN, Status.PAY_FAILURE));
        order.setCreationTime(ZonedDateTime.now());
        OrderVCO orderVCO = Transformer.to(OrderVCO.class).apply(order).done();
        return ApiResponse.createSuccess(orderVCO);
    }
}
